﻿using Gdk;

namespace GTKSystem.Windows.Forms.GTKControls.ControlBase
{
    public sealed class ButtonBase: Gtk.Button, IControlGtk
    {
        public GtkControlOverride Override { get; set; }
        public ButtonBase() : base(new Gtk.Label() { MaxWidthChars = 0, Wrap = true, LineWrap = true, LineWrapMode = Pango.WrapMode.WordChar })
        {
            this.Override = new GtkControlOverride(this);
            this.Override.AddClass("Button");
            base.Valign = Gtk.Align.Start;
            base.Halign = Gtk.Align.Start;
        }
        public System.Windows.Forms.DialogResult DialogResult { get; set; }
        protected override bool OnButtonPressEvent(EventButton evnt)
        {
            if (this.Toplevel is FormBase form)
            {
                ((System.Windows.Forms.Form)form.Data["Control"]).DialogResult = DialogResult;
            }
            base.OnButtonPressEvent(evnt);
            return false;
        }
        public new string Text { get => ((Gtk.Label)Child).Text; set => ((Gtk.Label)Child).Text = value; }
        protected override void OnShown()
        {
            Override.OnAddClass();
            base.OnShown();
        }
        protected override bool OnDrawn(Cairo.Context cr)
        {
            Gdk.Rectangle rec = new Gdk.Rectangle(0, 0, this.AllocatedWidth, this.AllocatedHeight);
            Override.OnPaint(cr, rec);
            return base.OnDrawn(cr);
        }
    }
}
